package servlet;

import pojo.Booking;
import service.BookingService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ListServlet", value = "/ListServlet")
public class ListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        Integer currPage = 0;
        if (request.getParameter("currPage")!=null){
            currPage = Integer.parseInt(request.getParameter("currPage"));
        }
        Integer pageSize = 3;
        if (request.getParameter("pageSize")!=null){
            pageSize = Integer.parseInt(request.getParameter("pageSize"));
        }
        String userName = null;
        if (request.getParameter("userName")!=null){
            userName = request.getParameter("userName");
        }
        BookingService service = new BookingService();
        List<Booking>list = service.list(currPage,pageSize,userName);
        request.setAttribute("list",list);
        request.setAttribute("currPage",currPage);
        request.setAttribute("userName",userName);
        request.getRequestDispatcher("index.jsp").forward(request,response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
